﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Infrastructure.CrossCutting.IoC;
using Cesave.DistributedServices.Core.ErrorHandlers;
using System.ServiceModel;
using Cesave.Domain.PermisosModule.Contracts.CultivosAguas;

namespace Cesave.DistributedServices.PermisosModule
{
	public partial class PermisosModuleService
	{
		#region IPermisosModuleService Members

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivosAgua"></param>
		public void AddCultivosAgua(Domain.PermisosModule.Entities.CultivosAgua cultivosAgua)
		{
			try
			{
				ICultivosAguaService cultivosAguaService = IoCFactory.Resolve<ICultivosAguaService>();
				cultivosAguaService.AddCultivosAgua(cultivosAgua);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivosAgua"></param>
		public void ChangeCultivosAgua(Domain.PermisosModule.Entities.CultivosAgua cultivosAgua)
		{
			try
			{
				ICultivosAguaService cultivosAguaService = IoCFactory.Resolve<ICultivosAguaService>();
				cultivosAguaService.ChangeCultivosAgua(cultivosAgua);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="cultivoGuid"></param>
		/// <param name="cicloGuid"></param>
		/// <param name="juntaGuid"></param>
		/// <returns></returns>
		public List<Domain.PermisosModule.Entities.CultivosAgua> FindCultivosAgua(Guid cultivoGuid, Guid cicloGuid, Guid juntaGuid)
		{
			try
			{
				ICultivosAguaService cultivosAguaService = IoCFactory.Resolve<ICultivosAguaService>();
				return cultivosAguaService.FindCultivosAgua(
					cultivoGuid,
					cicloGuid,
					juntaGuid
				);
			}
			catch (Exception ex)
			{
				ITraceManager traceManager = IoCFactory.Resolve<ITraceManager>();
				traceManager.TraceError(ex.Message);

				throw new FaultException<ServiceError>(ServiceError.Factory(ex.Message));
			}
		}

		#endregion
	}
}
